﻿@model ProductDetailsModel.ProductVariantModel.ProductVariantPriceModel
@using Nop.Web.Models.Catalog;
@using Nop.Core.Domain.Catalog;
@using Nop.Core.Infrastructure;
@using Nop.Core;
@using System.Text;
@using System.Globalization;
@using Nop.Services.Customers;
@using System.Text.RegularExpressions;
@{
    //string pattern = "(?<val>(\\d+[\\s\\,\\.]?)+)";
    //string replacement = String.Format("<span class=\"price-val-for-dyn-upd-{0}\">${{val}}</span> ", Model.ProductVariantId);
}
@if (Model.DynamicPriceUpdate)
{
    <script type="text/javascript">
        var priceValForDynUpd_@(Model.ProductVariantId) = @(((float)(Model.PriceValue != Model.PriceWithDiscountValue ? Model.PriceWithDiscountValue : Model.PriceValue)).ToString(new CultureInfo("en-US")));
    </script>
}
<div class="product-price">
    @if (Model.CustomerEntersPrice)
    {
        /*display nothing*/
    }
    else if (Model.CallForPrice)
    {
        <span class="product-price">@T("Products.CallForPrice")</span>
    }
    else
    {

        decimal savePercent = 0;
        decimal saveValue = 0;
        if (!String.IsNullOrEmpty(Model.OldPrice) && Model.OldPriceValue > 0)
        {
            if (!String.IsNullOrEmpty(Model.PriceWithDiscount))
            {
                saveValue = Model.OldPriceValue - Model.PriceWithDiscountValue;
                savePercent = Math.Ceiling(saveValue / Model.OldPriceValue * 100);
            }
            else
            {
                saveValue = Model.OldPriceValue - Model.PriceValue;
                savePercent = Math.Ceiling(saveValue / Model.OldPriceValue * 100);
            }
        }
        else
        {
            if (!String.IsNullOrEmpty(Model.PriceWithDiscount))
            {
                saveValue = Model.PriceValue - Model.PriceWithDiscountValue;
                savePercent = Math.Ceiling(saveValue / Model.PriceValue * 100);
            }
        }
        
        if (!String.IsNullOrEmpty(Model.PriceWithDiscount))
        {
            <span class="product-discount-price"><span class="price-title">Your Price:</span> <span class="price display-price">@Model.PriceWithDiscount</span></span><br />
        }

        if (savePercent > 0 && savePercent <= 100 && saveValue > 0 && !String.IsNullOrEmpty(Model.PriceWithDiscount))
        {
            <span>You save $@decimal.Round(saveValue, 2) (@savePercent%)</span>
        }

        <div class="product-regular-price @if (!String.IsNullOrEmpty(Model.PriceWithDiscount)){<text>cross-out</text>}"><span class="price-title">Listing Price:</span> <span class="price @if (String.IsNullOrEmpty(Model.PriceWithDiscount)){<text>display-price</text>}">@Model.Price</span></div>

        if (savePercent > 0 && savePercent <= 100 && saveValue > 0 && String.IsNullOrEmpty(Model.PriceWithDiscount))
        {
            <span>You save $@decimal.Round(saveValue, 2) (@savePercent%)</span>
        }

        if (!String.IsNullOrEmpty(Model.OldPrice))
        {
            <div class="product-old-price"><span class="price-title">Original Price:</span> <span class="price">@Model.OldPrice</span></div>
        }

        @*<span @if (String.IsNullOrWhiteSpace(Model.PriceWithDiscount)) { <text> class="product-price" </text>   }>
                @if (Model.DynamicPriceUpdate && !Model.HidePrices && String.IsNullOrWhiteSpace(Model.PriceWithDiscount))
                {
                    @Html.Raw(Regex.Replace(Model.Price, pattern, replacement))
                }
                else
                {
                    @Html.Raw(Model.Price)
                }
            </span>
            if (!String.IsNullOrWhiteSpace(Model.OldPrice))
            {
                <br /><span class="old-product-price">@Model.OldPrice</span>
            }


            if (!String.IsNullOrWhiteSpace(Model.PriceWithDiscount))
            {
                <br />
                @T("Products.Price.WithDiscount")<text>:</text>
                <span class="product-discount-price">
                    @if (Model.DynamicPriceUpdate && !Model.HidePrices)
                    {
                        @Html.Raw(Regex.Replace(Model.PriceWithDiscount, pattern, replacement))
                    }
                    else
                    {
                        @Html.Raw(Model.PriceWithDiscount)
                    }
                </span>
            }*@
    }
</div>
